package jdbc;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA
 * Description:使用select的sql语句
 * User:22954
 * Date:2024-05-11
 * Time:18:05
 */
public class ResultSet_ {
    public static void main(String[] args) throws IOException, SQLException {
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/jdbc/mysql.properties"));
        String url = properties.getProperty("url");
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();
        String sql = "select * from student";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            int no = resultSet.getInt(1);
            String name = resultSet.getString(2);
            System.out.println(no + "\t" + name);
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}
